

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Antoine
 */
public class Gui extends javax.swing.JFrame {

    /**
     * Creates new form Gui
     */
    public Gui() {
        initComponents();
        customInit();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btg_radiogroupe = new javax.swing.ButtonGroup();
        jlbl_titre = new javax.swing.JLabel();
        jrbt_aleatoire = new javax.swing.JRadioButton();
        jrbt_importer = new javax.swing.JRadioButton();
        jp_aleatoire = new javax.swing.JPanel();
        jtf_nbColonnes = new javax.swing.JTextField();
        jlbl_nbLignes = new javax.swing.JLabel();
        jtf_nbLignes = new javax.swing.JTextField();
        jlbl_nbColonnes = new javax.swing.JLabel();
        jb_genererAleatoire = new javax.swing.JButton();
        jlbl_aleatoireTitre = new javax.swing.JLabel();
        jlbl_valeurMini = new javax.swing.JLabel();
        jlbl_valeurMaxi = new javax.swing.JLabel();
        jtf_valeurMini = new javax.swing.JTextField();
        jtf_valeurMaxi = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jlbl_fileChooser = new javax.swing.JLabel();
        jtf_filePath = new javax.swing.JTextField();
        jb_parcourir = new javax.swing.JButton();
        jp_workplace = new javax.swing.JPanel();
        jlbl_matrice = new javax.swing.JLabel();
        jlbl_operations = new javax.swing.JLabel();
        jcb_operations = new javax.swing.JComboBox();
        jb_start = new javax.swing.JButton();
        jp_matriceImport = new javax.swing.JPanel();
        jtf_matriceSecondaire = new javax.swing.JTextField();
        jlbl_matriceSecondaire = new javax.swing.JLabel();
        jb_parcourirSecondaire = new javax.swing.JButton();

        btg_radiogroupe.add(jrbt_aleatoire);
        btg_radiogroupe.add(jrbt_importer);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jlbl_titre.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlbl_titre.setText("Créer une nouvelle matrice :");

        jrbt_aleatoire.setText("Aléatoire");
        jrbt_aleatoire.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbt_aleatoireActionPerformed(evt);
            }
        });

        jrbt_importer.setSelected(true);
        jrbt_importer.setText("Importer un fichier MTX");
        jrbt_importer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbt_importerActionPerformed(evt);
            }
        });

        jtf_nbColonnes.setText("10");

        jlbl_nbLignes.setText("Nombre de lignes :");

        jtf_nbLignes.setText("10");

        jlbl_nbColonnes.setText("Nombre de colonnes :");

        jb_genererAleatoire.setText("Générer");

        jlbl_aleatoireTitre.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlbl_aleatoireTitre.setText("Paramètres de la matrice aléatoire :");

        jlbl_valeurMini.setText("Valeur minimale :");

        jlbl_valeurMaxi.setText("Valeur maximale :");

        jtf_valeurMini.setText("-100");

        jtf_valeurMaxi.setText("100");

        javax.swing.GroupLayout jp_aleatoireLayout = new javax.swing.GroupLayout(jp_aleatoire);
        jp_aleatoire.setLayout(jp_aleatoireLayout);
        jp_aleatoireLayout.setHorizontalGroup(
            jp_aleatoireLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_aleatoireLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp_aleatoireLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp_aleatoireLayout.createSequentialGroup()
                        .addComponent(jlbl_aleatoireTitre)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jp_aleatoireLayout.createSequentialGroup()
                        .addGroup(jp_aleatoireLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlbl_nbLignes, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlbl_nbColonnes, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jp_aleatoireLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtf_nbLignes, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtf_nbColonnes, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(117, 117, 117)
                        .addGroup(jp_aleatoireLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jp_aleatoireLayout.createSequentialGroup()
                                .addComponent(jlbl_valeurMaxi, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtf_valeurMaxi, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jp_aleatoireLayout.createSequentialGroup()
                                .addComponent(jlbl_valeurMini, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jtf_valeurMini, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 62, Short.MAX_VALUE)
                        .addComponent(jb_genererAleatoire)
                        .addGap(27, 27, 27))))
        );
        jp_aleatoireLayout.setVerticalGroup(
            jp_aleatoireLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jp_aleatoireLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlbl_aleatoireTitre)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addGroup(jp_aleatoireLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbl_nbLignes)
                    .addComponent(jtf_nbLignes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlbl_valeurMini)
                    .addComponent(jtf_valeurMini, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jp_aleatoireLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbl_nbColonnes)
                    .addComponent(jtf_nbColonnes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jb_genererAleatoire)
                    .addComponent(jlbl_valeurMaxi)
                    .addComponent(jtf_valeurMaxi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17))
        );

        jlbl_fileChooser.setText("Chemin du fichier :");

        jtf_filePath.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtf_filePathActionPerformed(evt);
            }
        });

        jb_parcourir.setText("Parcourir");

        jlbl_matrice.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlbl_matrice.setText("Matrice actuelle :");

        jlbl_operations.setText("Opérations disponibles :");

        jcb_operations.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jb_start.setText("Go >>");

        jlbl_matriceSecondaire.setText("Multiplier avec :");

        jb_parcourirSecondaire.setText("Parcourir");

        javax.swing.GroupLayout jp_matriceImportLayout = new javax.swing.GroupLayout(jp_matriceImport);
        jp_matriceImport.setLayout(jp_matriceImportLayout);
        jp_matriceImportLayout.setHorizontalGroup(
            jp_matriceImportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_matriceImportLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp_matriceImportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlbl_matriceSecondaire, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jp_matriceImportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jb_parcourirSecondaire)
                        .addComponent(jtf_matriceSecondaire, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(192, Short.MAX_VALUE))
        );
        jp_matriceImportLayout.setVerticalGroup(
            jp_matriceImportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_matriceImportLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jlbl_matriceSecondaire)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jtf_matriceSecondaire, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jb_parcourirSecondaire)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jp_workplaceLayout = new javax.swing.GroupLayout(jp_workplace);
        jp_workplace.setLayout(jp_workplaceLayout);
        jp_workplaceLayout.setHorizontalGroup(
            jp_workplaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_workplaceLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp_workplaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlbl_matrice, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jp_workplaceLayout.createSequentialGroup()
                        .addComponent(jlbl_operations, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcb_operations, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(31, 31, 31)
                        .addComponent(jb_start))
                    .addComponent(jp_matriceImport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(67, Short.MAX_VALUE))
        );
        jp_workplaceLayout.setVerticalGroup(
            jp_workplaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_workplaceLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlbl_matrice)
                .addGap(23, 23, 23)
                .addGroup(jp_workplaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbl_operations)
                    .addComponent(jcb_operations, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jb_start))
                .addGap(18, 18, 18)
                .addComponent(jp_matriceImport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jlbl_titre, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jp_workplace, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jp_aleatoire, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jrbt_aleatoire)
                            .addGap(473, 473, 473)
                            .addComponent(jb_parcourir))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(jrbt_importer)
                            .addGap(66, 66, 66)
                            .addComponent(jlbl_fileChooser, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jtf_filePath, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jSeparator1))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlbl_titre, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbl_fileChooser)
                    .addComponent(jrbt_importer)
                    .addComponent(jtf_filePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jrbt_aleatoire)
                    .addComponent(jb_parcourir))
                .addGap(13, 13, 13)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jp_aleatoire, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jp_workplace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(23, 23, 23))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jrbt_aleatoireActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbt_aleatoireActionPerformed
        // TODO add your handling code here:
        if(jrbt_aleatoire.isSelected())
        {
            jp_aleatoire.setVisible(true);
            jtf_filePath.setVisible(false);
            jb_parcourir.setVisible(false);
            jlbl_fileChooser.setVisible(false);
        }
    }//GEN-LAST:event_jrbt_aleatoireActionPerformed

    private void jrbt_importerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbt_importerActionPerformed
        // TODO add your handling code here:
        if(jrbt_importer.isSelected())
        {
            jp_aleatoire.setVisible(false);
            jtf_filePath.setVisible(true);
            jb_parcourir.setVisible(true);
            jlbl_fileChooser.setVisible(true);
        }  
    }//GEN-LAST:event_jrbt_importerActionPerformed

    private void jtf_filePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtf_filePathActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtf_filePathActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Gui().setVisible(true);
            }
        });
    }
    
    
private void customInit()
{
	jp_aleatoire.setVisible(false);


	//Action bouton parcourir
	jb_parcourir.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e)
            {
                jfc_ouvrir = new JFileChooser();
                jfc_ouvrir.showDialog(Gui.this, "Ouvrir un fichier");
                fichier = jfc_ouvrir.getSelectedFile();
                if(fichier != null)
                jtf_filePath.setText(fichier.getAbsolutePath());
                try{
                     principale = Matrix.importMTX(jtf_filePath.getText());
                   }

                catch(Exception ex)
                {
                   
                }
                
            }
        });

        //Action bouton parcourir matrice secondaire
        jb_parcourirSecondaire.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e)
            {
                jfc_ouvrir = new JFileChooser();
                jfc_ouvrir.showDialog(Gui.this, "Ouvrir un fichier");
                fichier = jfc_ouvrir.getSelectedFile();
                if(fichier != null)
                jtf_matriceSecondaire.setText(fichier.getAbsolutePath());
                try{
                     secondaire = Matrix.importMTX(jtf_matriceSecondaire.getText());
                   }

                catch(Exception ex)
                {
                   
                }
                
            }
        });

        
        
        //Action bouton générer
        jb_genererAleatoire.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
            {
               principale = new Matrix(Integer.parseInt(jtf_nbLignes.getText()),Integer.parseInt(jtf_nbColonnes.getText()));
               principale.randomize(Double.parseDouble(jtf_valeurMini.getText()), Double.parseDouble(jtf_valeurMaxi.getText()));
        }});


        //Combobox des actions
        jcb_operations.removeAllItems();

                jcb_operations.addItem("1 - Multiplication");
		jcb_operations.addItem("2 - Rendre triangulaire inférieure");
		jcb_operations.addItem("3 - Rendre triangulaire supérieure");
		jcb_operations.addItem("4 - Résolution triangulaire inférieure");
		jcb_operations.addItem("5 - Résolution triangulaire supérieure");
		jcb_operations.addItem("6 - Décomposition LU");
                jcb_operations.addItem("7 - Méthode de Jacobi");
                jcb_operations.addItem("8 - Factorisation de Cholesky");
                jcb_operations.addItem("9 - Méthode de Gauss-Seidel");
         
        jcb_operations.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e)
            {
                switch(jcb_operations.getSelectedItem().toString().charAt(0))
                {
                    //Multiplication
                    case '1' :
                        jp_matriceImport.setVisible(true);
                        jlbl_matriceSecondaire.setText("Multiplier avec :");
                        break;
                    //Rendre triangulaire inférieure    
                    case '2' :
                        jp_matriceImport.setVisible(false);
                        break;
                    //Rendre triangulaire supérieure    
                    case '3' :
                        jp_matriceImport.setVisible(false);
                        break;
                    //Résolution triangulaire inférieure    
                    case '4' :
                        jp_matriceImport.setVisible(true);
                        jlbl_matriceSecondaire.setText("Vecteur b :");
                        break;
                    //Résolution triangulaire supérieure    
                    case '5' :
                        jp_matriceImport.setVisible(true);
                        jlbl_matriceSecondaire.setText("Vecteur b :");
                        break;
                    //Décomposition LU    
                    case '6' :
                        jp_matriceImport.setVisible(false);
                        break;
                    //Méthode de Jacobi    
                    case '7' :
                        jp_matriceImport.setVisible(true);
                        jlbl_matriceSecondaire.setText("Vecteur b :");
                        break;
                    //Factorisation de Cholesky    
                    case '8' :
                        jp_matriceImport.setVisible(false);
                        break;
                    //Méthode de Gauss-Seidel    
                    case '9' :
                        jp_matriceImport.setVisible(true);
                        jlbl_matriceSecondaire.setText("Vecteur b :");
                        break;
                }
            }
        });



		//Action bouton start
		jb_start.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e)
            {
                
               testImport(0);
               if(jcb_operations.getSelectedItem() != null && principale != null)
                {
                    switch(jcb_operations.getSelectedItem().toString().charAt(0))
                    {
                        //Rendre triangulaire inférieure
                        case '2' :
                            
                    try {
                            principale.setLowerTriangular();
                            principale.exportMTX("matTriInf", "coordinate real general");
                            JOptionPane.showMessageDialog(Gui.this, "La matrice est maintenant triangulaire inférieure\nFichier Généré : MatTriInf.mtx");
                        } 
                    
                        catch (FileNotFoundException ex) {
                            Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IOException ex) {
                            Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        break;
                            
                        //Rendre triangulaire supérieure    
                        case '3' :
                        
                        try 
                        {
                            principale.setUpperTriangular();
                            principale.exportMTX("matTriSup", "coordinate real general");
                            JOptionPane.showMessageDialog(Gui.this, "La matrice est maintenant triangulaire supérieure\nFichier Généré : MatTriSup.mtx");
                        }
                        
                        catch (FileNotFoundException ex) {
                            Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IOException ex) {
                            Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        break;
                        
                        //Résolution triangulaire inférieure    
                        case '4' :
                        testImport(1);    
                        if(secondaire != null)
                        {
                            if(principale.nbLine != secondaire.nbLine || secondaire.nbColumn > 1 || principale.nbLine != principale.nbColumn)
                            {
                                JOptionPane.showMessageDialog(Gui.this, "Attention, les matrices ne sont pas compatibles (voir dimensions)");
                            }
                            else{
                            x = Matrix.solveLowerTriangular(principale, secondaire);
                        try {
                            x.exportMTX("VecteurXResolInf", "array real general");
                            norme = Matrix.getNorme((principale.multiply(x)).subtraction(secondaire));
                            JOptionPane.showMessageDialog(Gui.this, "Fichier généré : VecteurXResolInf.mtx\n Test : ||Ax-b|| = "+norme);                  
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IOException ex) {
                            Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        }
                        }
                        
                        else {
                                JOptionPane.showMessageDialog(Gui.this, "Erreur, il faut préciser un vecteur b !");
                             }
                        break;
                        
                        //Résolution triangulaire supérieure    
                        case '5' :
                        testImport(1);
                        if(secondaire != null)
                        {
                            if(principale.nbLine != secondaire.nbLine || secondaire.nbColumn > 1 || principale.nbLine != principale.nbColumn)
                            {
                                JOptionPane.showMessageDialog(Gui.this, "Attention, les matrices ne sont pas compatibles (voir dimensions)");
                            }
                            else{
                            x = Matrix.solveUpperTriangular(principale, secondaire);
                        try {
                            x.exportMTX("VecteurXResolSup", "array real general");
                            norme = Matrix.getNorme((principale.multiply(x)).subtraction(secondaire));
                            JOptionPane.showMessageDialog(Gui.this, "Fichier généré : VecteurXResolSup.mtx\n Test : ||Ax-b|| = "+norme);
                        } 
                        catch (FileNotFoundException ex) {
                            Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IOException ex) {
                            Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                        }
                            }
                        }
                        
                        else {
                                JOptionPane.showMessageDialog(Gui.this, "Erreur, il faut préciser un vecteur b !");
                              }
   
                        break;
                        //Décomposition LU    
                        case '6' :
                        Matrix[] res = Matrix.LUDecomposition(principale);
                        try {
                                res[0].exportMTX("MatriceL", "coordinate real general");
                                res[1].exportMTX("MatriceU", "coordinate real general");
                                norme = Matrix.getNorme(principale.subtraction(res[0].multiply(res[1])));
                                JOptionPane.showMessageDialog(Gui.this, "Fichiers générés : MatriceL.mtx et MatriceU.mtx\n Test : ||A-LU|| = "+norme);
                            } 
                        
                        catch (FileNotFoundException ex) {
                        Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IOException ex) {
                        Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        break;
                        
                        //Méthode de Jacobi    
                        case '7' :
                            testImport(1);
                            if(secondaire != null)
                            {
                                if(principale.nbLine != secondaire.nbLine || secondaire.nbColumn > 1 || principale.nbLine != principale.nbColumn)
                            {
                                JOptionPane.showMessageDialog(Gui.this, "Attention, les matrices ne sont pas compatibles (voir dimensions)");
                            }
                            else{
                                x = principale.Jacobi(secondaire, 0.000001);
                            try {
                                x.exportMTX("Jacobi", "array real general");
                                norme = Matrix.getNorme((principale.multiply(x)).subtraction(secondaire));
                                JOptionPane.showMessageDialog(Gui.this, "Fichier généré : Jacobi.mtx\n Test : ||Ax-b|| = "+norme);
                            } catch (FileNotFoundException ex) {
                                Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (IOException ex) {
                                Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                            }
                            }
                            }
                         else {
                                JOptionPane.showMessageDialog(Gui.this, "Erreur, il faut préciser un vecteur b !");
                              }
                        break;
                            
                        //Factorisation de Cholesky    
                        case '8' :
                            x = principale.choleskyDecomposition();
                            try {
                                x.exportMTX("Cholesky", "coordinate real general");
                                JOptionPane.showMessageDialog(Gui.this, "Fichier généré : Cholesky.mtx");
                            } catch (FileNotFoundException ex) {
                                Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (IOException ex) {
                                Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        break;
                            
                        //Méthode de Gauss-Seidel    
                        case '9' :
                            testImport(1);
                            if(secondaire != null)
                            {
                                if(principale.nbLine != secondaire.nbLine || secondaire.nbColumn > 1 || principale.nbLine != principale.nbColumn)
                            {
                                JOptionPane.showMessageDialog(Gui.this, "Attention, les matrices ne sont pas compatibles (voir dimensions)");
                            }
                            else{
                                String info = principale.verifDiagonaleNonNulle();
                                x = principale.gaussSeidel(secondaire, 0.000001);
                            try {
                                x.exportMTX("GaussSeidel", "array real general");
                                norme = Matrix.getNorme((principale.multiply(x)).subtraction(secondaire));
                                if(info.equals(""))
                                {
                                    JOptionPane.showMessageDialog(Gui.this, "Fichier généré : GaussSeidel.mtx\n Test : ||Ax-b|| = "+norme);
                                }
                                
                                else
                                {
                                    JOptionPane.showMessageDialog(Gui.this, "Attention : "+info+"\nLe résultat est peut être faussé.\nFichier généré : GaussSeidel.mtx\n Test : ||Ax-b|| = "+norme);
                                }
                            } catch (FileNotFoundException ex) {
                                Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (IOException ex) {
                                Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                            }
                            }
                            }
                         else {
                                JOptionPane.showMessageDialog(Gui.this, "Erreur, il faut préciser un vecteur b !");
                              }
                            
                        break;
                            
                        //Multiplication    
                        case '1' :
                            testImport(1);
                            if(secondaire != null)
                            {
                                x = principale.multiply(secondaire);
                                if(x == null)
                                {
                                    JOptionPane.showMessageDialog(Gui.this, "Erreur, les matrices ont des dimensions incompatibles !");
                                }
                            else{
                            try {
                                x.exportMTX("ResultatMultiplication", "coordinate real general");
                                JOptionPane.showMessageDialog(Gui.this, "Fichier généré : ResultatMultiplication.mtx");
                                
                            } catch (FileNotFoundException ex) {
                                Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (IOException ex) {
                                Logger.getLogger(Gui.class.getName()).log(Level.SEVERE, null, ex);
                            }
                            }
                            }
                            
                            else {
                                JOptionPane.showMessageDialog(Gui.this, "Erreur, il faut préciser une seconde Matrice !");
                              }
                        break;
                            
                    }
                }
               
               else 
               {
                   JOptionPane.showMessageDialog(Gui.this, "Importez ou générez une matrice avant de lancer une opération");
               }
        }});

}

private void testImport(int i)
{
    if(i == 0)
    {
    if(principale == null && jtf_filePath.getText().compareTo("") != 0)
                {
                    try{
                     principale = Matrix.importMTX(jtf_filePath.getText());
                   }
                catch(Exception ex)
                {
                   
                }
               }
    }
    
    else 
    {
        if(secondaire == null && jtf_matriceSecondaire.getText().compareTo("") != 0)
                {
                    try{
                     secondaire = Matrix.importMTX(jtf_filePath.getText());
                   }
                catch(Exception ex)
                {
                   
                }
               }
    }
}
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup btg_radiogroupe;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton jb_genererAleatoire;
    private javax.swing.JButton jb_parcourir;
    private javax.swing.JButton jb_parcourirSecondaire;
    private javax.swing.JButton jb_start;
    private javax.swing.JComboBox jcb_operations;
    private javax.swing.JLabel jlbl_aleatoireTitre;
    private javax.swing.JLabel jlbl_fileChooser;
    private javax.swing.JLabel jlbl_matrice;
    private javax.swing.JLabel jlbl_matriceSecondaire;
    private javax.swing.JLabel jlbl_nbColonnes;
    private javax.swing.JLabel jlbl_nbLignes;
    private javax.swing.JLabel jlbl_operations;
    private javax.swing.JLabel jlbl_titre;
    private javax.swing.JLabel jlbl_valeurMaxi;
    private javax.swing.JLabel jlbl_valeurMini;
    private javax.swing.JPanel jp_aleatoire;
    private javax.swing.JPanel jp_matriceImport;
    private javax.swing.JPanel jp_workplace;
    private javax.swing.JRadioButton jrbt_aleatoire;
    private javax.swing.JRadioButton jrbt_importer;
    private javax.swing.JTextField jtf_filePath;
    private javax.swing.JTextField jtf_matriceSecondaire;
    private javax.swing.JTextField jtf_nbColonnes;
    private javax.swing.JTextField jtf_nbLignes;
    private javax.swing.JTextField jtf_valeurMaxi;
    private javax.swing.JTextField jtf_valeurMini;
    // End of variables declaration//GEN-END:variables
    private JFileChooser jfc_ouvrir;
    private File fichier;
    private Matrix principale;
    private Matrix secondaire;
    private Matrix x = null;
    private double norme = 0.0;
}
